package com.merry.websocket.controller;

import com.merry.websocket.pojo.Result;
import com.merry.websocket.pojo.User;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("user")
public class UserController {

    @PostMapping("/login")
    public Result login(@RequestBody User user, HttpSession session){
        Result result = new Result();
        if(user != null && "123".equalsIgnoreCase(user.getPassword())){
            result.setFlag(true);
            session.setAttribute("user",user.getUsername());
        }else{
            result.setFlag(false);
            result.setMessage("登录失败");
        }
        return result;
    }


    @GetMapping("/getUsername")
    public String getUsername(HttpSession session){
        String username = (String) session.getAttribute("user");
        return username;
    }
}
